package com.ruoyi.report.forms.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {

    WebClient client;

    public ChatController() {
        client = WebClient.create();
    }

    @PostMapping("reply")
    public String reply(@RequestBody List<Object> list) {
        String json = JSON.toJSONString(list);
        return client.post()
                .uri("http://localhost:12315/chat/reply")
                .contentType(MediaType.APPLICATION_JSON)
                .body(BodyInserters.fromValue(json))
                .retrieve()
                .bodyToMono(String.class)
                .block();
    }
}
